package com.graduation.service;

import com.graduation.dao.GoodsDao;
import com.graduation.dao.OrderDao;
import com.graduation.dao.UserDao;
import com.graduation.entity.Goods;
import com.graduation.entity.Order;
import com.graduation.entity.Recommend;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private GoodsDao goodsDao;
    @Resource
    private OrderDao orderDao;
    @Override
    public List<Recommend> doOrder(Integer... id) {
        List<Recommend> objects = null;
        if (id.length == 1) {
            Recommend recommend = goodsDao.queryRecommendById(String.valueOf(id[0]));
            objects = new ArrayList<>();
            objects.add(recommend);
        } else {
            objects = new ArrayList<>();
            for (int i = 0; i < id.length; i++) {
                Recommend recommend = goodsDao.queryRecommendById(String.valueOf(id[i]));
                objects.add(recommend);
            }
        }

        return objects;
    }

    @Override
    public Integer doSaveOrder(List list) {
        return orderDao.doSaveOrder(list);
    }

    @Override
    public List<Order> findGoodsByEmail(String email) {
        return orderDao.findGoodsByEmail(email);
    }
}
